package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.exartisan.bean.FbComment;
import com.exartisan.network.NetworkUtility;
import com.exartisan.roundedimageview.RoundedImageView;
import com.exartisan.thanhdoanhn.R;

public class EventFeedAdapter extends BaseAdapter {
	LayoutInflater inflater;
	ArrayList<FbComment> comments;

	public EventFeedAdapter() {
		
	}
	
	public EventFeedAdapter(Context ctx) {
		this.inflater = LayoutInflater.from(ctx);
		comments = new ArrayList<FbComment>();
	}

	@Override
	public int getCount() {
		return comments.size();
	}

	@Override
	public Object getItem(int position) {
		return comments.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	public void setFbComments(ArrayList<FbComment> comments){
		this.comments = comments;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.row_event_feed, null, false);
			holder.imgAvatar = (RoundedImageView) convertView.findViewById(R.id.imgAvatar);
			holder.tvUserName = (TextView) convertView.findViewById(R.id.tvUserName);
			holder.tvPostTime = (TextView) convertView.findViewById(R.id.tvPostTime);
			holder.tvContent = (TextView) convertView.findViewById(R.id.tvContent);
			holder.tvNumberLikeFeed = (TextView) convertView.findViewById(R.id.tvNumberLikeFeed);
			holder.tvNumberCommentFeed = (TextView) convertView.findViewById(R.id.tvNumberCommentFeed);
			convertView.setTag(holder);
		} else holder = (ViewHolder) convertView.getTag();
		
		holder.tvUserName.setText(comments.get(position).getFbUser().getName());
		holder.tvPostTime.setText(comments.get(position).getCreated_time());
		holder.tvContent.setText(comments.get(position).getMessage());
		//holder.tvNumberLikeFeed.setText(comments.get(position).getLike_count());
		//holder.tvNumberCommentFeed.setText(comments.get(position).getComment_count());
		holder.imgAvatar.setImageUrl(NetworkUtility.GRAPH_API_URL + "/" + comments.get(position).getFbUser().getId() + "/picture");
		return convertView;
	}
	
	private class ViewHolder{
		RoundedImageView imgAvatar;
		TextView tvUserName;
		TextView tvPostTime;
		TextView tvContent;
		TextView tvNumberLikeFeed;
		TextView tvNumberCommentFeed;
	}

}
